package cn.pfz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: 普发忠
 * @Date: 2021/10/20/21:44
 */
@Configuration
public class asd {
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            //重写父类提供的跨域请求处理接口
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                //添加映射路径
                registry.addMapping("/**")
                        .allowedOrigins("*").
                        //代表是否运行发送Cokie信息
                                allowCredentials(true).
                        //放行那些提交方式
                                allowedMethods("GET","POST","PUT","DELETE","OPTIONS").
                        //放行那些头部信息
                                allowedHeaders("*").
                        //放行自定义的头部信息
                                exposedHeaders("xxxxx","xxxxxx");
            }
        };
        
    }
}
